package cn.wolfcode.rbac.config;

import cn.wolfcode.rbac.interceptor.CheckPermissionInterceptor;
import cn.wolfcode.rbac.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Lu.F
 * @version 1.0
 * @Description TODO
 * @date 2022/5/21 11:14
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }

    @Bean
    public CheckPermissionInterceptor checkPermissionInterceptor(){
        return new CheckPermissionInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        registry.addInterceptor(loginInterceptor())
                .addPathPatterns("/**") //要拦截的请求路径
                .excludePathPatterns("/","/login","/js/**","/css/**");//排除拦截的请求路径

        registry.addInterceptor(checkPermissionInterceptor())
                .addPathPatterns("/**") //要拦截的请求路径
                .excludePathPatterns("/","/login","/js/**","/css/**");//排除拦截的请求路径

        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
